﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@{
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();

    var operatorInfo = UIUtility.GetCurrentUser();

    var menuNames = ViewData["menuName"];

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());

    ViewData["menuNames"] = menuNames;
     
}
@using (Html.BeginForm("Search", "Transfer", FormMethod.Post, new { @id = "searchForm" }))
{

    <table width="100%">
        <tr>
            <td style="width: 10%; text-align: right">
                交接日期起：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("FromCreatedDate").HtmlAttributes(new { @style = "width:170px;" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td style="width: 10%; text-align: right">
                交接日期止：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("ToCreatedDate").HtmlAttributes(new { @style = "width:170px;" }).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToShortDateString())
            </td>
            <td style="width: 10%; text-align: right">
                厂商：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("Supplier").HtmlAttributes(new { @style = "width:190px;" }).BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr>
            <td style="width: 10%; text-align: right">
                交接方向：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("TRANSFER_TYPE").HtmlAttributes(new { @style = "width:160px;" }).BindTo(ddlHelper.GetDataSourcePart(ConfigMgr.tblTransferBillType,AgentNo, true, ViewBag.TransferTypeS == null ? UIConstants.AllItems : ViewBag.TransferTypeS as string, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
@*                .Enable((ViewBag.TransferTypeS == null ? UIConstants.AllItems : ViewBag.TransferTypeS as string).Equals(UIConstants.AllItems))*@
            </td>
            <td style="width: 10%; text-align: right">
                营业厅类别：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("AgentType").HtmlAttributes(new { @style = "width:160px;" }).BindTo(ddlHelper.GetAgentTypes(UIConstants.AllItems, false,AgentNo,new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).CascadeTo("Agent")
            </td>
            <td style="width: 10%; text-align: right">
                营业厅：
            </td>
            <td style="width: 20%; text-align: left">
              @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:230px;" }).DataBinding(binding => binding.Ajax().Select("_GetAgent", "RepairOrders", new {AgentNo=AgentNo }))
               @* @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "width:190px;" }).ClientEvents(events => events.OnLoad("agentonload"))*@
            </td>
        </tr>
        <tr>
            <td style="width: 10%; text-align: right">
                交接单状态：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("TransferBillStatus").HtmlAttributes(new { @style = "width:160px;" }).BindTo(ddlHelper.GetDataSource(ConfigMgr.tblTransferBillStatus, true, ViewBag.TransferStatus == null ? UIConstants.AllItems : ViewBag.TransferStatus as string, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
              @*  .Enable((ViewBag.TransferStatus == null ? UIConstants.AllItems : ViewBag.TransferStatus as string).Equals(UIConstants.AllItems))*@
            </td>
            <td style="width: 10%; text-align: center">
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                @Html.Hidden("AgentNo", AgentNo, new { @id = "AgentNo" })
            </td>
        </tr>
    </table>
    
    
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });

        if ("@AgentNo".length != 0) {
//            alert("@AgentNo");
            var agentType = $('#AgentType').data('tDropDownList');
            var transferBillStatus = $('#TransferBillStatus').data('tDropDownList');
            agentType.select(1); agentType.disable(); //alert(transferBillStatus.value());
        }
    });

    function agentonload(e) {
        //debugger;
        var agent = $('#Agent').data('tDropDownList');
        $.post("/RepairOrders/_GetAgentC", { "AgentType": "全部", "AgentNo": "@AgentNo" }, function (data) {
            agent.dataBind(data);
//            agent.select(0);
//            if ("@AgentNo" != "") {
//                agent.disable();
//            }
//            else {
//                agent.disable = false;
//            }
        })
    }

    function search() {

        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
